package com.wiserun.develop.contract.controller;

import com.alibaba.fastjson.JSON;
import com.wiserun.common.model.ResponseData;
import com.wiserun.common.util.FormatUtil;
import com.wiserun.develop.contract.model.Contract;
import com.wiserun.develop.contract.model.ContractDTO;
import com.wiserun.develop.contract.service.ContractService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(description = "合同管理")
@Controller
@ResponseBody
@RequestMapping("/contract")
public class ContractController {
    @Autowired
    private ContractService contractService;

    @RequestMapping("/list")
    public List<Contract> getList(){
        List<Contract> contractList = contractService.getContractList();
        return  contractList;
    }

    @PostMapping("/listByContract")
    public ResponseData getList(@RequestBody(required=false) ContractDTO contract){
        System.err.println(contract);
        List<Contract> contractList = contractService.getContractList(contract);
        Integer numList = contractService.getNumList(contract);
        Map<String,Object> map =new HashMap<>();
        map.put("list",contractList);
        map.put("total",numList);
        return FormatUtil.success(map);
    }

    @RequestMapping("/updateContract")
    public Integer updateContract(@RequestBody Contract contract){
        return contractService.updateContract(contract);
    }
    @RequestMapping("/addContract")
    public Integer addContract(@RequestBody Contract createdItem){
        return contractService.addContract(createdItem);
    }

    @RequestMapping("/deleteContract")
    public Integer DeleteContract(@RequestBody String str){
        Integer contid = Integer.parseInt(JSON.parseObject(str).get("contid").toString());
        return contractService.deleteContract(contid);
    }
}
